package com.huashi.demo;


import org.apache.commons.lang3.StringUtils;

import java.util.*;

class Solution {
    public String reverseWords(String s) {

        String[] ss = s.split(" ");
        String result = "";
        Stack<String> stack = new Stack<>();
        for (String s1 : ss) {
            if (!" ".equals(s1)){
                stack.add(s1);
            }
        }
        while (!stack.isEmpty()) {
            result = result + stack.pop() + " ";
        }
        return result.replaceFirst(" ", "\\s+$");
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.reverseWords("i am a  ss."));
    }
}

